{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb603ff2-cc4d-4e24-b0b4-32d85c533362",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "==============================\n",
      "欢迎使用学生成绩管理系统\n",
      "==============================\n",
      "请选择操作：\n",
      "1. 记录学生成绩\n",
      "2. 查询学生成绩\n",
      "3. 统计课程成绩\n",
      "4. 退出系统\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入选项序号： 1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "====== 记录学生成绩 ======\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入学生姓名： 姚瑜巧\n",
      "请输入学生学号： 202410139120\n",
      "请输入课程名称： Python编程\n",
      "请输入成绩（0-100）： 80\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "成绩已成功记录！\n",
      "==============================\n",
      "欢迎使用学生成绩管理系统\n",
      "==============================\n",
      "请选择操作：\n",
      "1. 记录学生成绩\n",
      "2. 查询学生成绩\n",
      "3. 统计课程成绩\n",
      "4. 退出系统\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入选项序号： 2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请选择查询方式：\n",
      "1. 按学生姓名查询\n",
      "2. 按学生学号查询\n",
      "3. 按课程名称查询\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入选项序号： 1\n",
      "请输入学生姓名： 姚瑜巧\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名: 姚瑜巧, 学号: 202410139120, 课程: Python编程, 成绩: 80.0\n",
      "==============================\n",
      "欢迎使用学生成绩管理系统\n",
      "==============================\n",
      "请选择操作：\n",
      "1. 记录学生成绩\n",
      "2. 查询学生成绩\n",
      "3. 统计课程成绩\n",
      "4. 退出系统\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入选项序号： 3\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "====== 统计课程成绩 ======\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入课程名称： Python编程\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "课程: Python编程\n",
      "平均分: 80.00\n",
      "最高分: 80.0\n",
      "最低分: 80.0\n",
      "==============================\n",
      "欢迎使用学生成绩管理系统\n",
      "==============================\n",
      "请选择操作：\n",
      "1. 记录学生成绩\n",
      "2. 查询学生成绩\n",
      "3. 统计课程成绩\n",
      "4. 退出系统\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入选项序号： 4\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "感谢使用学生成绩管理系统，再见！\n",
      "==============================\n",
      "欢迎使用学生成绩管理系统\n",
      "==============================\n",
      "请选择操作：\n",
      "1. 记录学生成绩\n",
      "2. 查询学生成绩\n",
      "3. 统计课程成绩\n",
      "4. 退出系统\n"
     ]
    }
   ],
   "source": [
    "class Student:\n",
    "    def __init__(self, name, id, course, score):\n",
    "        self.name = name\n",
    "        self.id = id\n",
    "        self.course = course\n",
    "        self.score = score\n",
    "\n",
    "\n",
    "students = []\n",
    "\n",
    "\n",
    "def print_menu():\n",
    "    print(\"=\" * 30)\n",
    "    print(\"欢迎使用学生成绩管理系统\")\n",
    "    print(\"=\" * 30)\n",
    "    print(\"请选择操作：\")\n",
    "    print(\"1. 记录学生成绩\")\n",
    "    print(\"2. 查询学生成绩\")\n",
    "    print(\"3. 统计课程成绩\")\n",
    "    print(\"4. 退出系统\")\n",
    "\n",
    "\n",
    "def record_score():\n",
    "    print(\"====== 记录学生成绩 ======\")\n",
    "    name = input(\"请输入学生姓名：\")\n",
    "    id_num = input(\"请输入学生学号：\")\n",
    "    course = input(\"请输入课程名称：\")\n",
    "    while True:\n",
    "        try:\n",
    "            score = float(input(\"请输入成绩（0-100）：\"))\n",
    "            if 0 <= score <= 100:\n",
    "                break\n",
    "            print(\"成绩必须在0到100之间，请重新输入。\")\n",
    "        except ValueError:\n",
    "            print(\"输入无效，请输入一个有效的数字。\")\n",
    "    student = Student(name, id_num, course, score)\n",
    "    students.append(student)\n",
    "    print(\"成绩已成功记录！\")\n",
    "\n",
    "\n",
    "def query_score():\n",
    "    print(\"请选择查询方式：\")\n",
    "    print(\"1. 按学生姓名查询\")\n",
    "    print(\"2. 按学生学号查询\")\n",
    "    print(\"3. 按课程名称查询\")\n",
    "    choice = input(\"请输入选项序号：\")\n",
    "    if choice == \"1\":\n",
    "        name = input(\"请输入学生姓名：\")\n",
    "        found = False\n",
    "        for student in students:\n",
    "            if student.name == name:\n",
    "                print(f\"姓名: {student.name}, 学号: {student.id}, 课程: {student.course}, 成绩: {student.score}\")\n",
    "                found = True\n",
    "        if not found:\n",
    "            print(\"未找到该学生的成绩记录。\")\n",
    "    elif choice == \"2\":\n",
    "        id_num = input(\"请输入学生学号：\")\n",
    "        found = False\n",
    "        for student in students:\n",
    "            if student.id == id_num:\n",
    "                print(f\"姓名: {student.name}, 学号: {student.id}, 课程: {student.course}, 成绩: {student.score}\")\n",
    "                found = True\n",
    "        if not found:\n",
    "            print(\"未找到该学生的成绩记录。\")\n",
    "    elif choice == \"3\":\n",
    "        course = input(\"请输入课程名称：\")\n",
    "        found = False\n",
    "        for student in students:\n",
    "            if student.course == course:\n",
    "                print(f\"姓名: {student.name}, 学号: {student.id}, 课程: {student.course}, 成绩: {student.score}\")\n",
    "                found = True\n",
    "        if not found:\n",
    "            print(\"未找到该课程的成绩记录。\")\n",
    "    else:\n",
    "        print(\"无效的选项，请重新输入。\")\n",
    "\n",
    "\n",
    "def statistics_score():\n",
    "    print(\"====== 统计课程成绩 ======\")\n",
    "    course = input(\"请输入课程名称：\")\n",
    "    scores = [student.score for student in students if student.course == course]\n",
    "    if scores:\n",
    "        average = sum(scores) / len(scores)\n",
    "        highest = max(scores)\n",
    "        lowest = min(scores)\n",
    "        print(f\"课程: {course}\")\n",
    "        print(f\"平均分: {average:.2f}\")\n",
    "        print(f\"最高分: {highest}\")\n",
    "        print(f\"最低分: {lowest}\")\n",
    "    else:\n",
    "        print(\"未找到该课程的成绩记录。\")\n",
    "\n",
    "\n",
    "def exit_system():\n",
    "    print(\"感谢使用学生成绩管理系统，再见！\")\n",
    "    exit()\n",
    "\n",
    "\n",
    "while True:\n",
    "    print_menu()\n",
    "    choice = input(\"请输入选项序号：\")\n",
    "    if choice == \"1\":\n",
    "        record_score()\n",
    "    elif choice == \"2\":\n",
    "        query_score()\n",
    "    elif choice == \"3\":\n",
    "        statistics_score()\n",
    "    elif choice == \"4\":\n",
    "        exit_system()\n",
    "    else:\n",
    "        print(\"无效的选项，请重新输入。\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69fe0f43-aadd-491e-b48e-c219f4840fae",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
